//
//  SecondaryClassificationView.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/20.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "SecondaryClassificationView.h"

@interface SecondaryClassificationView ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) NSMutableArray <ProClassificationModel*>*dataArray;

@end

@implementation SecondaryClassificationView


- (void)fillWithArray:(NSMutableArray <ProClassificationModel *>*)dataArray {
    self.dataArray = dataArray;
    [self.tableview reloadData];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self layout];
}

- (void)layout {
    
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableview.backgroundColor =  UIColorHex(0xf1f1f1);
    
    self.tableview.showsHorizontalScrollIndicator = NO;
    self.tableview.showsVerticalScrollIndicator = NO;
    
    self.tableview.estimatedSectionHeaderHeight = 0;
    self.tableview.estimatedSectionFooterHeight = 0;
    self.tableview.estimatedRowHeight = 0;
    
    [self.tableview registerNib:[UINib nibWithNibName:@"SecondaryClassificationCell" bundle:nil] forCellReuseIdentifier:@"SecondaryClassificationCellID"];
    
}

- (void)fillWithModel {
    [self.tableview reloadData];
}

#pragma mark UITableviewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 49;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    SecondaryClassificationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SecondaryClassificationCellID"];
    cell.selectionStyle =UITableViewCellSelectionStyleNone;
    [cell fillCellWithModel:self.dataArray[indexPath.row]];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (self.SecondaryClassificationViewBlock) {
        self.SecondaryClassificationViewBlock(indexPath.row);
    }
}

- (NSMutableArray<ProClassificationModel *> *)dataArray {
    if (!_dataArray) {
        _dataArray = @[].mutableCopy;
    }
    return _dataArray;
}

@end
